import axios from "axios"
import nProgress from "nprogress"
import "nprogress/nprogress.css"

const mockAjax = axios.create({
  baseURL: "/mock",
  timeout: 1000,
})

// 添加请求拦截器
mockAjax.interceptors.request.use(req => {
  nProgress.start()
  return req
})

// 添加响应拦截器
mockAjax.interceptors.response.use(
  response => {
    nProgress.done()
    return response.data
  },
  error => {
    nProgress.done()
    return Promise.reject(new Error(error.message))
  }
)

export default mockAjax
